﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Shell : MonoBehaviour
{
    public float moveSpeed = 10;
    public int parentID;
    public SpriteRenderer sr;

    // Start is called before the first frame update
    void Start()
    {
        sr = GetComponent<SpriteRenderer>();
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(transform.up * moveSpeed * Time.deltaTime, Space.World);
    }

    
    private void OnTriggerEnter2D(Collider2D collision)
    {
        switch (collision.tag)
        {
            case "Tank":
                if (parentID == collision.GetComponent<BaseTank>().GetInstanceID())
                {
                    break;
                }
                collision.SendMessage("Die");
                Destroy(gameObject);
                break;
            case "HeadQuarter":
                collision.SendMessage("Die");
                // 如果司令部已经被摧毁，子弹直接穿过
                if (collision.GetComponent<HeadQuarter>().IsDead)
                {
                    break;
                }
                Destroy(gameObject);
                break;
            case "Iron":
                break;
            case "Invulnerable":
                Destroy(gameObject);
                break;
            case "Brick":
                Destroy(collision.gameObject);
                Destroy(gameObject);
                break;
            default:
                break;
        }
    }
}
